package com.rectcircle.scalatrateset.controller

import com.rectcircle.scalatrateset.command._
import com.rectcircle.scalatrateset.command.commandsupport._
import com.rectcircle.scalatrateset.model._

import org.scalatra._

import org.scalatra.commands._



/**
  * @author Rectcircle
  *         createTime 2017/1/6
  */
class TodoController extends ScalatratestStack {
	
	get("/:id") {
		TodoData.all find (_.id == params("id").toInt) match {
			case Some(todo) => todo
			case None => halt(404)
		}
	}
	
	post("/") {
		val todo = new Todo(-1, params("name"))
		TodoData.add(TodoData.newTodo(params("name")))
		redirect("/")
	}
	
	post("/todos") {
		
		
		//val cmd = command[CreateTodoCommand]
		
//		(command[CreateTodoCommand] >> (TodoData.add(_))).fold(
//			errors => halt(400, errors),
//			todo => redirect("/")
//		)
	}
	
}